package com.qige.homework;

import com.qige.homework.test.Rectangle;

public class day16_homework5 {
    public static void main(String[] args) {
        User[] users = new User[15];
        for (int i = 0; i < users.length; i++) {
            users[i] = new User();
            users[i].setId(i+1);
        }
        V1_Filter v1 = new V1_Filter();
        V2_Filter v2 = new V2_Filter();
        A_Filter A = new A_Filter();
        Receptionist r1 = new Receptionist(v1);
        Receptionist r2 = new Receptionist(v2);
        Receptionist r3 = new Receptionist(A);
        for (int i = 0; i < users.length; i++) {
            if (users[i].getId() >0 && users[i].getId() <=5){
                r1.recept(users[i]);
            }
            if (users[i].getId() >5 && users[i].getId() <=10){
                r2.recept(users[i]);
            }
            if (users[i].getId() >10 && users[i].getId() <=15){
                r3.recept(users[i]);
            }
        }
        for (int i = 0; i < users.length; i++) {
            System.out.println(users[i].getId() + "-" + users[i].getType());
        }
    }
}
class User {
    private String type;
    private int id;

    public User() {
    }

    public User(String type, int id) {
        this.type = type;
        this.id = id;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
interface Filter{
    abstract void filter(User user);
}
class V1_Filter implements Filter{

    @Override
    public void filter(User user) {
        user.setType("v1");
    }
}
class V2_Filter implements Filter{

    @Override
    public void filter(User user) {
        user.setType("v2");
    }
}
class A_Filter implements Filter{

    @Override
    public void filter(User user) {
        user.setType("A");
    }
}
class Receptionist{
    private Filter filter;

    public Receptionist(Filter filter) {
        this.filter = filter;
    }

    public Filter getFilter() {
        return filter;
    }

    public void setFilter(Filter filter) {
        this.filter = filter;
    }
    public void recept(User u){
        if(u.getType() != null){
            return ;
        }
        filter.filter(u);
    }
}